package androidx.preference;

import android.content.DialogInterface;
import android.os.Bundle;
import androidx.appcompat.app.b;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class d extends f {
    CharSequence[] A;
    Set<String> x = new HashSet();
    boolean y;
    CharSequence[] z;

    class a implements DialogInterface.OnMultiChoiceClickListener {
        a() {
        }

        public void onClick(DialogInterface dialogInterface, int i, boolean z) {
            boolean z2;
            boolean z3;
            d dVar = d.this;
            if (z) {
                z2 = dVar.y;
                z3 = dVar.x.add(dVar.A[i].toString());
            } else {
                z2 = dVar.y;
                z3 = dVar.x.remove(dVar.A[i].toString());
            }
            dVar.y = z3 | z2;
        }
    }

    private MultiSelectListPreference s() {
        return (MultiSelectListPreference) l();
    }

    public static d t(String str) {
        d dVar = new d();
        Bundle bundle = new Bundle(1);
        bundle.putString("key", str);
        dVar.setArguments(bundle);
        return dVar;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (bundle == null) {
            MultiSelectListPreference s = s();
            if (s.L0() == null || s.M0() == null) {
                throw new IllegalStateException("MultiSelectListPreference requires an entries array and an entryValues array.");
            }
            this.x.clear();
            this.x.addAll(s.N0());
            this.y = false;
            this.z = s.L0();
            this.A = s.M0();
            return;
        }
        this.x.clear();
        this.x.addAll(bundle.getStringArrayList("MultiSelectListPreferenceDialogFragmentCompat.values"));
        this.y = bundle.getBoolean("MultiSelectListPreferenceDialogFragmentCompat.changed", false);
        this.z = bundle.getCharSequenceArray("MultiSelectListPreferenceDialogFragmentCompat.entries");
        this.A = bundle.getCharSequenceArray("MultiSelectListPreferenceDialogFragmentCompat.entryValues");
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putStringArrayList("MultiSelectListPreferenceDialogFragmentCompat.values", new ArrayList(this.x));
        bundle.putBoolean("MultiSelectListPreferenceDialogFragmentCompat.changed", this.y);
        bundle.putCharSequenceArray("MultiSelectListPreferenceDialogFragmentCompat.entries", this.z);
        bundle.putCharSequenceArray("MultiSelectListPreferenceDialogFragmentCompat.entryValues", this.A);
    }

    public void p(boolean z2) {
        if (z2 && this.y) {
            MultiSelectListPreference s = s();
            if (s.b(this.x)) {
                s.O0(this.x);
            }
        }
        this.y = false;
    }

    /* access modifiers changed from: protected */
    public void q(b.a aVar) {
        super.q(aVar);
        int length = this.A.length;
        boolean[] zArr = new boolean[length];
        for (int i = 0; i < length; i++) {
            zArr[i] = this.x.contains(this.A[i].toString());
        }
        aVar.i(this.z, zArr, new a());
    }
}
